package com.cskaoyan.controller.promote;

import com.cskaoyan.bean.MallTopic;
import com.cskaoyan.model.bo.promote.SimpleMallTopic;
import com.cskaoyan.model.vo.BaseRespVo;
import com.cskaoyan.model.vo.promote_ad.BaseData;
import com.cskaoyan.model.vo.promote_ad.TopicRead;
import com.cskaoyan.service.promote.TopicService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * TODO
 *
 * @author：23117
 * @date: 2021/11/30
 */
@RestController
@RequestMapping("admin/topic")
public class TopicController {
    @Autowired
    TopicService topicService;

    @RequiresPermissions("admin:topic:list")
    @RequestMapping("list")
    public BaseRespVo list(Integer page,Integer limit){
        BaseData data = topicService.list(page,limit);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions("admin:topic:read")
    @RequestMapping("read")
    //有问题
    public BaseRespVo read(Integer id){
        TopicRead data = topicService.read(id);
        return BaseRespVo.ok(data);
    }

    @RequiresPermissions("admin:topic:update")
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody MallTopic mallTopic){
        boolean status = topicService.update(mallTopic);
        if (status) return BaseRespVo.ok();
        return BaseRespVo.fail("更新失败");
    }

    @RequiresPermissions("admin:topic:delete")
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody MallTopic mallTopic){
        boolean status = topicService.delete(mallTopic);
        if (status) return BaseRespVo.ok();
        return BaseRespVo.fail("删除失败");
    }

    @RequiresPermissions("admin:topic:create")
    @PostMapping("create")
    public BaseRespVo create(@RequestBody SimpleMallTopic simpleMallTopic){
        MallTopic vo = topicService.create(simpleMallTopic);

        return BaseRespVo.ok(vo);
    }
}



